home *** CD-ROM | disk | FTP | other *** search
/ CD Classic / CD CLASSIC #1.iso / chess / eval.c < prev    next >
C/C++ Source or Header  |  1991-08-15  |  36KB  |  1,335 lines

  1. /*
  2.   C source for GNU CHESS
  3.  
  4.   Revision: 1990-09-30
  5.  
  6.   Modified by Daryl Baker for use in MS WINDOWS environment
  7.  
  8.   Copyright (C) 1986, 1987, 1988, 1989, 1990 Free Software Foundation, Inc.
  9.   Copyright (c) 1988, 1989, 1990  John Stanback
  10.  
  11.   This file is part of CHESS.
  12.  
  13.   CHESS is distributed in the hope that it will be useful, but WITHOUT ANY
  14.   WARRANTY.  No author or distributor accepts responsibility to anyone for
  15.   the consequences of using it or for whether it serves any particular
  16.   purpose or works at all, unless he says so in writing.  Refer to the CHESS
  17.   General Public License for full details.
  18.  
  19.   Everyone is granted permission to copy, modify and redistribute CHESS, but
  20.   only under the conditions described in the CHESS General Public License.
  21.   A copy of this license is supposed to have been given to you along with
  22.   CHESS so you can know your rights and responsibilities.  It should be in a
  23.   file named COPYING.  Among other things, the copyright notice and this
  24.   notice must be preserved on all copies.
  25. */
  26.  
  27. #define NOATOM 
  28. #define NOCLIPBOARD
  29. #define NOCREATESTRUCT
  30. #define NOFONT
  31. #define NOREGION
  32. #define NOSOUND
  33. #define NOWH
  34. #define NOWINOFFSETS
  35. #define NOCOMM
  36. #define NOKANJI
  37.  
  38. #include <windows.h>
  39. #include <stdio.h>
  40.  
  41. #include "gnuchess.h"
  42. #include "defs.h"
  43.  
  44. /*#define taxicab(a,b) taxidata[a][b]*/
  45. #define taxicab(a,b) *(taxidata+a*64+b)
  46.  
  47. #define wking PieceList[white][0]
  48. #define bking PieceList[black][0]
  49. #define EnemyKing PieceList[c2][0]
  50.  
  51. /*extern short distdata[64][64], taxidata[64][64];*/
  52. extern short far *distdata, far *taxidata;
  53.  
  54. /*extern unsigned char nextpos[8][64][64];*/
  55. /*extern unsigned char nextdir[8][64][64];*/
  56. extern unsigned char far * nextpos;
  57. extern unsigned char far * nextdir;
  58.  
  59.  
  60. extern short PieceList[2][16], PawnCnt[2][8];
  61. extern short Pscore[maxdepth], Tscore[maxdepth];
  62. extern short mtl[2], pmtl[2], emtl[2], hung[2];
  63. extern short c1, c2, *atk1, *atk2, *PC1, *PC2, atak[2][64];
  64. extern short ChkFlag[maxdepth], CptrFlag[maxdepth], PawnThreat[maxdepth];
  65. extern short Pindex[64];
  66. extern short PieceCnt[2];
  67. extern short FROMsquare, TOsquare, Zscore, zwndw;
  68. extern short Mking[2][64], Kfield[2][64];
  69. extern short ATAKD, HUNGP, HUNGX, KCASTLD, KMOVD, XRAY, PINVAL;
  70. extern short RHOPN, RHOPNX, KHOPN, KHOPNX, KSFTY;
  71. extern short HasKnight[2], HasBishop[2], HasRook[2], HasQueen[2];
  72. extern short Mwpawn[64], Mbpawn[64], Mknight[2][64], Mbishop[2][64];
  73. extern short Mking[2][64], Kfield[2][64];
  74. extern short KNIGHTPOST, KNIGHTSTRONG, BISHOPSTRONG, KATAK;
  75. extern short PEDRNK2B, PWEAKH, PADVNCM, PADVNCI, PAWNSHIELD, PDOUBLED, PBLOK;
  76. extern short stage, stage2, Developed[2];
  77. extern short PawnBonus, BishopBonus, RookBonus;
  78.  
  79.  
  80. static short _based(_segname("_CODE")) KingOpening[64] =
  81. {0, 0, -4, -10, -10, -4, 0, 0,
  82.  -4, -4, -8, -12, -12, -8, -4, -4,
  83.  -12, -16, -20, -20, -20, -20, -16, -12,
  84.  -16, -20, -24, -24, -24, -24, -20, -16,
  85.  -16, -20, -24, -24, -24, -24, -20, -16,
  86.  -12, -16, -20, -20, -20, -20, -16, -12,
  87.  -4, -4, -8, -12, -12, -8, -4, -4,
  88.  0, 0, -4, -10, -10, -4, 0, 0};
  89.  
  90. static short _based(_segname("_CODE")) KingEnding[64] =
  91. {0, 6, 12, 18, 18, 12, 6, 0,
  92.  6, 12, 18, 24, 24, 18, 12, 6,
  93.  12, 18, 24, 30, 30, 24, 18, 12,
  94.  18, 24, 30, 36, 36, 30, 24, 18,
  95.  18, 24, 30, 36, 36, 30, 24, 18,
  96.  12, 18, 24, 30, 30, 24, 18, 12,
  97.  6, 12, 18, 24, 24, 18, 12, 6,
  98.  0, 6, 12, 18, 18, 12, 6, 0};
  99.  
  100. static short _based(_segname("_CODE")) DyingKing[64] =
  101. {0, 8, 16, 24, 24, 16, 8, 0,
  102.  8, 32, 40, 48, 48, 40, 32, 8,
  103.  16, 40, 56, 64, 64, 56, 40, 16,
  104.  24, 48, 64, 72, 72, 64, 48, 24,
  105.  24, 48, 64, 72, 72, 64, 48, 24,
  106.  16, 40, 56, 64, 64, 56, 40, 16,
  107.  8, 32, 40, 48, 48, 40, 32, 8,
  108.  0, 8, 16, 24, 24, 16, 8, 0};
  109.  
  110. static short _based(_segname("_CODE")) KBNK[64] =
  111. {99, 90, 80, 70, 60, 50, 40, 40,
  112.  90, 80, 60, 50, 40, 30, 20, 40,
  113.  80, 60, 40, 30, 20, 10, 30, 50,
  114.  70, 50, 30, 10, 0, 20, 40, 60,
  115.  60, 40, 20, 0, 10, 30, 50, 70,
  116.  50, 30, 10, 20, 30, 40, 60, 80,
  117.  40, 20, 30, 40, 50, 60, 80, 90,
  118.  40, 40, 50, 60, 70, 80, 90, 99};
  119.  
  120. static short _based(_segname("_CODE")) pknight[64] =
  121. {0, 4, 8, 10, 10, 8, 4, 0,
  122.  4, 8, 16, 20, 20, 16, 8, 4,
  123.  8, 16, 24, 28, 28, 24, 16, 8,
  124.  10, 20, 28, 32, 32, 28, 20, 10,
  125.  10, 20, 28, 32, 32, 28, 20, 10,
  126.  8, 16, 24, 28, 28, 24, 16, 8,
  127.  4, 8, 16, 20, 20, 16, 8, 4,
  128.  0, 4, 8, 10, 10, 8, 4, 0};
  129.  
  130. static short _based(_segname("_CODE")) pbishop[64] =
  131. {14, 14, 14, 14, 14, 14, 14, 14,
  132.  14, 22, 18, 18, 18, 18, 22, 14,
  133.  14, 18, 22, 22, 22, 22, 18, 14,
  134.  14, 18, 22, 22, 22, 22, 18, 14,
  135.  14, 18, 22, 22, 22, 22, 18, 14,
  136.  14, 18, 22, 22, 22, 22, 18, 14,
  137.  14, 22, 18, 18, 18, 18, 22, 14,
  138.  14, 14, 14, 14, 14, 14, 14, 14};
  139.  
  140. static short _based(_segname("_CODE")) PawnAdvance[64] =
  141. {0, 0, 0, 0, 0, 0, 0, 0,
  142.  4, 4, 4, 0, 0, 4, 4, 4,
  143.  6, 8, 2, 10, 10, 2, 8, 6,
  144.  6, 8, 12, 16, 16, 12, 8, 6,
  145.  8, 12, 16, 24, 24, 16, 12, 8,
  146.  12, 16, 24, 32, 32, 24, 16, 12,
  147.  12, 16, 24, 32, 32, 24, 16, 12,
  148.  0, 0, 0, 0, 0, 0, 0, 0};
  149.  
  150. static short _based(_segname("_CODE")) value[7] =
  151. {0, valueP, valueN, valueB, valueR, valueQ, valueK};
  152.  
  153. static short _based(_segname("_CODE")) control[7] =
  154. {0, ctlP, ctlN, ctlB, ctlR, ctlQ, ctlK};
  155.  
  156. static short _based(_segname("_CODE")) PassedPawn0[8] =
  157. {0, 60, 80, 120, 200, 360, 600, 800};
  158.  
  159. static short _based(_segname("_CODE")) PassedPawn1[8] =
  160. {0, 30, 40, 60, 100, 180, 300, 800};
  161.  
  162. static short _based(_segname("_CODE")) PassedPawn2[8] =
  163. {0, 15, 25, 35, 50, 90, 140, 800};
  164.  
  165. static short _based(_segname("_CODE")) PassedPawn3[8] =
  166. {0, 5, 10, 15, 20, 30, 140, 800};
  167.  
  168. static short _based(_segname("_CODE")) ISOLANI[8] =
  169. {-12, -16, -20, -24, -24, -20, -16, -12};
  170.  
  171. static short _based(_segname("_CODE")) BACKWARD[16] =
  172. {-6, -10, -15, -21, -28, -28, -28, -28,
  173.  -28, -28, -28, -28, -28, -28, -28, -28};
  174.  
  175. static short _based(_segname("_CODE")) BMBLTY[14] =
  176. {-2, 0, 2, 4, 6, 8, 10, 12, 13, 14, 15, 16, 16, 16};
  177.  
  178. static short _based(_segname("_CODE")) RMBLTY[15] =
  179. {0, 2, 4, 6, 8, 10, 11, 12, 13, 14, 14, 14, 14, 14, 14};
  180.  
  181. static short _based(_segname("_CODE")) KTHRT[36] =
  182. {0, -8, -20, -36, -52, -68, -80, -80, -80, -80, -80, -80,
  183.  -80, -80, -80, -80, -80, -80, -80, -80, -80, -80, -80, -80,
  184.  -80, -80, -80, -80, -80, -80, -80, -80, -80, -80, -80, -80};
  185.  
  186. /*
  187.   ptype is used to separate white and black pawns, like this;
  188.   ptyp = ptype[side][piece]
  189.   piece can be used directly in nextpos/nextdir when generating moves
  190.   for pieces that are not black pawns.
  191. */
  192. static short _based(_segname("_CODE")) ptype[2][8] =
  193. {
  194.   no_piece, pawn, knight, bishop, rook, queen, king, no_piece,
  195.   no_piece, bpawn, knight, bishop, rook, queen, king, no_piece};
  196.  
  197. static short _based(_segname("_CODE")) direc[8][8] =
  198. {
  199.   0, 0, 0, 0, 0, 0, 0, 0,
  200.   10, 9, 11, 0, 0, 0, 0, 0,
  201.   8, -8, 12, -12, 19, -19, 21, -21,
  202.   9, 11, -9, -11, 0, 0, 0, 0,
  203.   1, 10, -1, -10, 0, 0, 0, 0,
  204.   1, 10, -1, -10, 9, 11, -9, -11,
  205.   1, 10, -1, -10, 9, 11, -9, -11,
  206.   -10, -9, -11, 0, 0, 0, 0, 0};
  207.  
  208. static short _based(_segname("_CODE")) max_steps[8] =
  209. {0, 2, 1, 7, 7, 7, 1, 2};
  210.  
  211. static short _based(_segname("_CODE")) nunmap[120] =
  212. {
  213.   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  214.   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  215.   -1, 0, 1, 2, 3, 4, 5, 6, 7, -1,
  216.   -1, 8, 9, 10, 11, 12, 13, 14, 15, -1,
  217.   -1, 16, 17, 18, 19, 20, 21, 22, 23, -1,
  218.   -1, 24, 25, 26, 27, 28, 29, 30, 31, -1,
  219.   -1, 32, 33, 34, 35, 36, 37, 38, 39, -1,
  220.   -1, 40, 41, 42, 43, 44, 45, 46, 47, -1,
  221.   -1, 48, 49, 50, 51, 52, 53, 54, 55, -1,
  222.   -1, 56, 57, 58, 59, 60, 61, 62, 63, -1,
  223.   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  224.   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
  225.  
  226. static short _based(_segname("_CODE")) qrook[3] = {0, 56, 0};
  227.  
  228. static short _based(_segname("_CODE")) krook[3] = {7, 63, 0};
  229.  
  230. static short _based(_segname("_CODE")) kingP[3] = {4, 60, 0};
  231.  
  232. static short _based(_segname("_CODE")) rank7[3] = {6, 1, 0};
  233.  
  234. static short _based(_segname("_CODE")) sweep[8] =
  235. {false, false, false, true, true, true, false, false};
  236.  
  237.  
  238. /* ............    POSITIONAL EVALUATION ROUTINES    ............ */
  239.  
  240. int
  241. evaluate (short int side,
  242.           short int ply,
  243.           short int alph